unit ApplicationDebug;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : ApplicationDebug.pas
//
// Description :
//
// Called By : Main : Main.mnuConfigureDebugClick
//
// Calls : HUPasswordDlg : ShowModal
//         HUtils : ValidPasswordCharacter
//
// Ver. : 1.0.0
//
// Date : 30 Sep 2015
//
//========================================================================================

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Buttons, ExtCtrls,
  // Application Unitys
  HUPasswordDlg, HUtils;

type

  { TfrmApplicationDebug }

  TfrmApplicationDebug = class(TForm)
    bbtOK: TBitBtn;
    bbtCancel: TBitBtn;
    CheckBox1: TCheckBox;
    chkWaterTestTable: TCheckBox;
    chkWaterQuality: TCheckBox;
    chkWaterParametersTable: TCheckBox;
    chkWaterMaintenanceTable: TCheckBox;
    chkTankData: TCheckBox;
    chkHUtils: TCheckBox;
    chkFeedingCategoryTable: TCheckBox;
    chkFeedingCategoryRecord: TCheckBox;
    chkCurrentTank: TCheckBox;
    chkApplicationSettings: TCheckBox;
    chkFinal: TCheckBox;
    chkInit: TCheckBox;
    chkMain: TCheckBox;
    edtPassword: TEdit;
    Panel1: TPanel;
    StaticText1: TStaticText;
    procedure bbtOKClick(Sender: TObject);
    procedure chkFeedingCategoryTableChange(Sender: TObject);
    procedure chkMainChange(Sender: TObject);
    procedure edtPasswordExit(Sender: TObject);
    procedure edtPasswordKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtPasswordKeyPress(Sender: TObject; var Key: char);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
    fDebugMain : boolean;
    fDebugFeedingCategoryTable : boolean;
  public
    { public declarations }
    procedure DebugApplication;
  published
    property DebugMain: boolean read fDebugMain write fDebugMain;
    property DebugFeedingCategoryTable: boolean read fDebugFeedingCategoryTable
                                                 write fDebugFeedingCategoryTable;
  end;

var
  frmApplicationDebug: TfrmApplicationDebug;

implementation

{$R *.lfm}

const
  cstDefaultPassword = 'Da2yiiaa';

{ TfrmApplicationDebug }

//========================================================================================
//          SUPPORT ROUTINES
//========================================================================================

//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================

//========================================================================================
//          PUBLISHED ROUTINES
//========================================================================================

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========== POPUP MENUS ===================================================================

//========================================================================================
//          TOOLBAR ROUTINES
//========================================================================================

//========================================================================================
//           STATUSBAR ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================
procedure TfrmApplicationDebug.bbtOKClick(Sender: TObject);
begin
 if DebugMain then
   showmessage('Debug Main');
end;// procedure TfrmApplicationDebug.bbtOKClick

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========== chkMain =====================================================================
procedure TfrmApplicationDebug.chkMainChange(Sender: TObject);
begin
  if chkMain.Checked then
    DebugMain := True
  else
    DebugMain := false;
end;// procedure TfrmApplicationDebug.chkMainChange

//========== chkFeedingCategoryTableChange =====================================================================
procedure TfrmApplicationDebug.chkFeedingCategoryTableChange(Sender: TObject);
begin
  if chkFeedingCategoryTable.Checked then
    DebugFeedingCategoryTable := True
  else
    DebugFeedingCategoryTable := false;
end;// procedure TfrmApplicationDebug.chkFeedingCategoryTableChange

//========== edtPassword =================================================================
procedure TfrmApplicationDebug.edtPasswordExit(Sender: TObject);
begin
  if edtPassword.Text <> cstDefaultPassword then
  begin
    showmessage('Invalid Password');
    bbtCancel.SetFocus;
  end;
end;// procedure TfrmApplicationDebug.edtPasswordExit

//----------------------------------------------------------------------------------------
procedure TfrmApplicationDebug.edtPasswordKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if Key = Ord(keyEnter) then
    Key := Ord(keyTab);
end;

//----------------------------------------------------------------------------------------
procedure TfrmApplicationDebug.edtPasswordKeyPress(Sender: TObject;
  var Key: char);
begin
  Key := ValidPasswordCharacter (Key);
end;// procedure TfrmApplicationDebug.edtPasswordKeyPress

//========================================================================================
//          DATABASE ROUTINES
//========================================================================================

//========================================================================================
//          FORM ROUTINES
//========================================================================================
procedure TfrmApplicationDebug.DebugApplication;
begin

  HUPasswordDialog.Pwd2Match := cstDefaultPassword;
  HUPasswordDialog.ShowModal;

  if HUPasswordDialog.ModalResult = mrNoPasswordToMatch then
  begin
    showmessage('No Password to Match');
    Exit;
  end;// if HUPasswordDialog.ModalResult = mrNoPasswordToMatch

  if HUPasswordDialog.ModalResult = mrNumberOfTriesExceeded then
  begin
    showmessage('No Matching Password. Too Many Tries');
    Exit;
  end;// if HUPasswordDialog.ModalResult = mrNumberOfTriesExceeded


  if HUPasswordDialog.ModalResult = mrCancel then
  begin
    showmessage('Password Cancelled');
    Exit;
  end;// if HUPasswordDialog.ModalResult = mrCancel

  frmApplicationDebug.ShowModal;

end;// procedure TfrmApplicationDebug.DebugApplication;

//========================================================================================
procedure TfrmApplicationDebug.FormShow(Sender: TObject);
begin

end;// procedure TfrmApplicationDebug.FormShow

//========================================================================================
end.

